<template>
  <com-card>
    <div slot="com_title">修改订单</div>
    <div slot="com_content">
      <el-form
        v-if="formObj.id"
        :model="formObj"
        label-width="100px"
        style="width: 400px"
      >
        <el-form-item label="订单号">
          <el-input type="text" v-model="formObj.orderNo"></el-input>
        </el-form-item>
        <el-form-item label="下单时间：">
          <el-input type="text" v-model="formObj.orderTime"></el-input>
        </el-form-item>
        <el-form-item label="手机号：">
          <el-input type="text" v-model="formObj.phone"></el-input>
        </el-form-item>
        <el-form-item label="收货人：">
          <el-input type="text" v-model="formObj.consignee"></el-input>
        </el-form-item>
        <el-form-item label="送货地址：">
          <el-input type="text" v-model="formObj.deliverAddress"></el-input>
        </el-form-item>
        <el-form-item label="送达时间：">
          <el-input type="text" v-model="formObj.deliveryTime"></el-input>
        </el-form-item>
        <el-form-item label="用户备注">
          <el-input type="text" v-model="formObj.remarks"></el-input>
        </el-form-item>
        <el-form-item label="订单金额">
          <el-input type="text" v-model="formObj.orderAmount"></el-input>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-select v-model="formObj.orderState">
            <el-option label="派送中" value="派送中"></el-option>
            <el-option label="已受理" value="已受理"></el-option>
            <el-option label="已完成" value="已完成"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </com-card>
</template>

<script>
import ComCard from "../../components/comCard";
import { api_queryOne, api_edit } from "../../api/order";
export default {
  components: {
    ComCard,
  },
  data() {
    return {
      formObj: {
        data: "",
        id: "",
        orderNo: "",
        orderTime: "",
        phone: "",
        consignee: "",
        deliverAddress: "",
        deliveryTime: "",
        remarks: "",
        orderAmount: "",
        orderState: "",
      },
    };
  },
  mounted() {
    this.queryOne();
  },
  methods: {
    async queryOne() {
      // 根据id获取订单详情的方法
      // 拿到订单列表传递过来的id值
      let rst = await api_queryOne({ id: this.$route.query.id });
      this.formObj = rst.data;
      console.log(rst);
    },
    async save(){
       let rst= await api_edit(this.formObj);
       console.log(rst);
       let{code,msg}=rst;
       if(code==0){
           this.$message.success(msg);
           this.$router.replace("/order/list");
       }else{
           this.$message.error(msg);
       }
    }
  },
};
</script>

<style lang="less" scoped></style>
